import Router from './router/index';
const MODE = "hash";
class App {
    constructor() {
        this.initEvent();
        this.router = new Router(MODE);
        this.initSwiper();
    }
    initEvent() {
        var self = this;
        location.hash = "#position";//初始化
        $("#nav").on('click', 'li', function () {
            $(this).addClass("active").siblings().removeClass("active");
            let path = $(this).attr("data-hash");
            if (MODE === "hash") {//通过hash实现跳转
                location.hash = path;
            } else {
                history.pushState({}, "", path);//第一个参数是参数，第二个是title,第三个是路径
                self.router.loadView(path);
            }
            let index = $(this).index();
            self.mySwiper.slideTo(index, 500, false);//切换到第一个slide，速度为1秒
        })
    }
    initSwiper() {
        var self = this;
        // var index = 
        this.mySwiper = new Swiper('.swiper-container', {
            on: {
                slideChangeTransitionEnd: function () {
                    // alert(this.activeIndex);//切换结束时，告诉我现在是第几个slide
                    // var path = $(".swiper-slide").eq(this.activeIndex).attr("data-hash");
                    $("#nav li").eq(this.activeIndex).addClass("active").siblings().removeClass("active");
                    switch (this.activeIndex) {
                        case 0:
                            self.router.loadView();

                            break;
                        case 1:
                            self.router.loadView("search");
                            break;
                        case 2:
                            self.router.loadView("my");
                            break;
                    }
                },
            },
        })
    }
}
new App();